home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Amiga Plus Special 25
/
AMIGAplus Sonderheft 25 (2000)(Falke)(DE)(Track 1 of 4)[!].iso
/
PublicDomain
/
Spiele
/
TextElite
/
TextElite.c
< prev
next >
Wrap
C/C++ Source or Header
|
2000-02-27
|
26KB
|
977 lines
/*
* Textual version of Elite trading (C implementation)
* Converted by Ian Bell from 6502 Elite sources.
* Original 6502 Elite by Ian Bell & David Braben.
*
* Modified by Duane McDonnell (TextElite.c) based upon original
* txtelite.c code by Ian Bell. Changes made:
*
* - Added commander load, save and reset commands.
* - Extended government and economy names.
* - Increased maximum string length to 128 chars (for filenames).
* - parser() no longer destroys the input string. Pressing enter
* on its own now brings up the help menu (rather than buying food).
* - 'Local' command now tells you which systems are in range (IR)
* or out of range (OR) according to your current fuel load.
* - Text output tweaked a bit (more verbose, columns line up etc).
*
* Second release version, corrects a few problems. The first version
* didn't have a version number, this one is numbered 1.1:
*
* - Hold status is now accurate. First version didn't account for
* different units (all goods were calculated as tonnes).
* - dosave() will now delete partial saves in the event of a write error.
* - Embedded an Amiga version string in the code.
* - Amiga executable now compiled with stack extension on.
*/
/* ----------------------------------------------------------------------
The nature of basic mechanisms used to generate the Elite socio-economic
universe are now widely known. A competant games programmer should be able to
produce equivalent functionality. A competant hacker should be able to lift
the exact system from the object code base of official conversions.
This file may be regarded as defining the Classic Elite universe.
It contains a C implementation of the precise 6502 algorithms used in the
original BBC Micro version of Acornsoft Elite together with a parsed textual
command testbed.
Note that this is not the universe of David Braben's 'Frontier' series.
ICGB 13/10/99
iancgbell@email.com
www.ibell.co.uk
---------------------------------------------------------------------- */
/* Note that this program is "quick-hack" text parser-driven version
of Elite with no combat or missions.
*/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <time.h>
#include <math.h>
char ver[] = "$VER: TextElite 1.1 (27.2.2000)\r\n\0";
#define true (-1)
#define false (0)
#define tonnes (0)
#define maxlen (128) /* Length of strings */
typedef int boolean;
typedef unsigned short uint16;
typedef signed short int16;
typedef signed long int32;
typedef uint16 uint;
typedef int planetnum;
typedef struct
{ uint16 w0;
uint16 w1;
uint16 w2;
} seedtype; /* six byte random number used as seed for planets */
typedef struct
{ uint x;
uint y; /* One byte unsigned */
uint economy; /* These two are actually only 0-7 */
uint govtype;
uint techlev; /* 0-16 i think */
uint population; /* One byte */
uint productivity; /* Two byte */
uint radius; /* Two byte (not used by game at all) */
char name[12];
} plansys ;
#define galsize (256)
#define AlienItems (16)
#define lasttrade AlienItems
#define numforLave 7 /* Lave is 7th generated planet in galaxy one */
#define numforZaonce 129
#define numforDiso 147
#define numforRied 46
plansys galaxy[galsize]; /* Need 0 to galsize-1 inclusive */
seedtype seed;
typedef struct
{ /* In 6502 version these were: */
uint baseprice; /* one byte */
int16 gradient; /* five bits plus sign */
uint basequant; /* one byte */
uint maskbyte; /* one byte */
uint units; /* two bits */
char name[20]; /* longest="Radioactives" */
} tradegood ;
typedef struct
{ uint quantity[lasttrade+1];
uint price[lasttrade+1];
} markettype ;
/* Player workspace */
uint shipshold[lasttrade+1]; /* Contents of cargo bay */
planetnum currentplanet; /* Current planet */
uint galaxynum; /* Galaxy number (1-8) */
int32 cash;
uint fuel;
markettype localmarket;
uint holdspace;
uint holdtotal;
int fuelcost =2; /* 0.2 CR/Light year */
int maxfuel =70; /* 7.0 LY tank */
const uint16 base0=0x5A4A;
const uint16 base1=0x0248;
const uint16 base2=0xB753; /* Base seed for galaxy 1 */
char pairs[] = "..LEXEGEZACEBISO"
"USESARMAINDIREA."
"ERATENBERALAVETI"
"EDORQUANTEISRION"; /* Dots should be nullprint characters */
char govnames[][maxlen]={"Anarchy ",
"Feudal ",
"Multi-Government",
"Dictatorship ",
"Communist ",
"Confederacy ",
"Democracy ",
"Corporate State "};
char econnames[][maxlen]={"Rich Industrial ",
"Average Industrial ",
"Poor Industrial ",
"Mainly Industrial ",
"Mainly Agricultural ",
"Rich Agricultural ",
"Average Agricultural",
"Poor Agricultural "};
char unitnames[][5] ={"t","kg","g"};
/* Data for DB's price/availability generation system */
/* Base Grad Base Mask Un Name
price ient quant it */
#define POLITICALLY_CORRECT 0
/* Set to 1 for NES-sanitised trade goods */
tradegood commodities[]=
{
{0x13,-0x02,0x06,0x01,0,"Food "},
{0x14,-0x01,0x0A,0x03,0,"Textiles "},
{0x41,-0x03,0x02,0x07,0,"Radioactives"},
#if POLITICALLY_CORRECT
{0x28,-0x05,0xE2,0x1F,0,"Robot Slaves"},
{0x53,-0x05,0xFB,0x0F,0,"Beverages "},
#else
{0x28,-0x05,0xE2,0x1F,0,"Slaves "},
{0x53,-0x05,0xFB,0x0F,0,"Liquor/Wines"},
#endif
{0xC4,+0x08,0x36,0x03,0,"Luxuries "},
#if POLITICALLY_CORRECT
{0xEB,+0x1D,0x08,0x78,0,"Rare Species"},
#else
{0xEB,+0x1D,0x08,0x78,0,"Narcotics "},
#endif
{0x9A,+0x0E,0x38,0x03,0,"Computers "},
{0x75,+0x06,0x28,0x07,0,"Machinery "},
{0x4E,+0x01,0x11,0x1F,0,"Alloys "},
{0x7C,+0x0d,0x1D,0x07,0,"Firearms "},
{0xB0,-0x09,0xDC,0x3F,0,"Furs "},
{0x20,-0x01,0x35,0x03,0,"Minerals "},
{0x61,-0x01,0x42,0x07,1,"Gold "},
{0xAB,-0x02,0x37,0x1F,1,"Platinum "},
{0x2D,-0x01,0xFA,0x0F,2,"Gem-Stones "},
{0x35,+0x0F,0xC0,0x07,0,"Alien Items "},
};
/**-Required data for text interface **/
char tradnames[lasttrade][maxlen]; /* Tradegood names used in text commands
Set using commodities array */
boolean parser(char *s);
#define nocomms 16
boolean dobuy(char *);
boolean dosell(char *);
boolean dofuel(char *);
boolean dojump(char *);
boolean docash(char *);
boolean domkt(char *);
boolean dohelp(char *);
boolean dohold(char *);
boolean dosneak(char *);
boolean dolocal(char *);
boolean doinfo(char *);
boolean dogalhyp(char *);
boolean doload(char *);
boolean dosave(char *);
boolean doreset(char *);
boolean doquit(char *);
char commands[nocomms][maxlen]=
{"buy", "sell", "fuel", "jump",
"cash", "mkt", "help", "hold",
"sneak", "local", "info", "galhyp",
"load", "save", "!reset", "quit"
};
boolean (*comfuncs[nocomms])(char *)=
{dobuy, dosell, dofuel, dojump,
docash, domkt, dohelp, dohold,
dosneak, dolocal, doinfo, dogalhyp,
doload, dosave, doreset, doquit
};
/**- General functions **/
char randbyte(void) { return (char)(rand()&0xFF);}
uint mymin(uint a,uint b) { if(a<b) return(a); else return(b);}
void stop(char * string)
{ printf("\n%s",string);
exit(1);
}
/**+ ftoi **